/**
 * @file tileset.cpp
 * @brief TileSet class methods implementation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * @author VestniK (Sergey N.Vidyuk) sir.vestnik@gmail.com
 * @date 24 Oct 2008
 */
#include "tileset.h"

#include "defaults.h"
#include "tile.h"

using namespace mjn;

void TileSet::fillSet() throw(IncorrectTileset) {
   if ( ! tiles.isEmpty() ) {
      this->clearSet();
   }
   // Creating game tiles
   for ( int i = 0; i < TILE_REPEAT_NUMBER; i++ ) {
      // Creating regulair tiles
      for ( unsigned j = MIN_TILE_NUMBER; j <= MAX_TILE_NUMBER; j++ ) {
         tiles.append( Tile(Tile::Dot, (Tile::TileRanks)j) );
         tiles.append( Tile(Tile::Bamboo, (Tile::TileRanks)j) );
         tiles.append( Tile(Tile::Character, (Tile::TileRanks)j) );
      }
      // Creating winds
      tiles.append( Tile(Tile::Wind, Tile::East) );
      tiles.append( Tile(Tile::Wind, Tile::South) );
      tiles.append( Tile(Tile::Wind, Tile::West) );
      tiles.append( Tile(Tile::Wind, Tile::North) );
      // Creating dragons
      tiles.append( Tile(Tile::Dragon, Tile::Red) );
      tiles.append( Tile(Tile::Dragon, Tile::Green) );
      tiles.append( Tile(Tile::Dragon, Tile::White) );
   }
   // Creating bonus tiles
   // Seasons
   tiles.append( Tile(Tile::Season, Tile::Spring) );
   tiles.append( Tile(Tile::Season, Tile::Summer) );
   tiles.append( Tile(Tile::Season, Tile::Autumn) );
   tiles.append( Tile(Tile::Season, Tile::Winter) );
   // Flowers
   tiles.append( Tile(Tile::Flower, Tile::Plum) );
   tiles.append( Tile(Tile::Flower, Tile::Orchid) );
   tiles.append( Tile(Tile::Flower, Tile::BambooFlower) );
   tiles.append( Tile(Tile::Flower, Tile::Chrisantemium) );
   // Check that all tiles are valid
   foreach ( Tile t, tiles ) {
      if ( ! t.isValid() ) {
         throw( IncorrectTileset() );
      }
   }
}

void TileSet::clearSet() {
   tiles.clear();
}
